package jh.com.jhappbf.view;

import android.app.Dialog;
import android.content.Context;

import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;



import androidx.annotation.NonNull;
import jh.com.jhappbf.R;


/**
 * 作者：Created by GP on 2018/11/14.
 */
public class PointDialog extends Dialog {
    static TextView title;
    static TextView content;
    static TextView cancel;
    static TextView commit;

    private PointDialog(@NonNull Context context) {
        super(context);
    }

    public static PointDialog show(Context context, View.OnClickListener listener) {
        final PointDialog dialog = new PointDialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(context, R.layout.dialog_point, null);
        title=view.findViewById(R.id.title);
        content=view.findViewById(R.id.content);
        cancel=view.findViewById(R.id.cancel);
        commit=view.findViewById(R.id.commit);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        commit.setOnClickListener(listener);
        dialog.setContentView(view);
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = display.getWidth() * 9 / 10;
        params.gravity = Gravity.CENTER;
        dialog.getWindow().setAttributes(params);
        dialog.show();
        return dialog;
    }
    public static PointDialog show(Context context, String contents, View.OnClickListener listener) {
        final PointDialog dialog = new PointDialog(context);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(context, R.layout.dialog_point, null);
        title=view.findViewById(R.id.title);
        content=view.findViewById(R.id.content);
        content.setText(contents);
        cancel=view.findViewById(R.id.cancel);
        commit=view.findViewById(R.id.commit);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        commit.setOnClickListener(listener);
        dialog.setContentView(view);
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = display.getWidth() * 9 / 10;
        params.gravity = Gravity.CENTER;
        dialog.getWindow().setAttributes(params);
        dialog.show();
        return dialog;
    }


}